package com.hrg.rds.infra.executor.impl;

import com.hrg.rds.biz.waybill.domain.instance.WaybillInstance;
import com.hrg.rds.biz.waybill.domain.instance.WaybillInstanceStatus;
import com.hrg.rds.biz.waybill.domain.template.cmd.CmdParam;
import com.hrg.rds.infra.executor.CmdExecutor;
import com.hrg.rds.infra.executor.CmdInstanceContext;
import com.hrg.rds.infra.executor.CmdInstanceResult;
import com.hrg.rds.biz.waybill.service.WaybillInstanceService;
import com.hrg.sys.common.constant.UserConstants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Slf4j
@Service("StartCmd")
public class StartCmdExecutor implements CmdExecutor {

	@Autowired
	private WaybillInstanceService waybillInstanceService;

	@Override
	public CmdInstanceResult execute(List<CmdParam> params, CmdInstanceContext cmdInstanceContext) {
		log.info("StartCmdExecutor execute");
		// 更新运单实例 start_time
		String waybillInstanceId = cmdInstanceContext.getWaybillInstanceId();
		WaybillInstance waybillInstance = new WaybillInstance();
		waybillInstance.setId(waybillInstanceId);
		Date now = new Date();
		waybillInstance.setStartTime(now);
		waybillInstance.setUpdateBy(UserConstants.SYS_USER);
		waybillInstance.setUpdateTime(now);
		waybillInstance.setWaybillInstanceStatus(WaybillInstanceStatus.Executing);
		waybillInstanceService.updateById(waybillInstance);
		return CmdInstanceResult.success();
	}
}
